package cdu.sl.mapper;

import cdu.sl.entity.Employee;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface EmployeeDao extends JpaRepository<Employee, Integer>, JpaSpecificationExecutor<Employee> {


    /**
     * 分页条件查询员工数据
     * @param name 员工姓名
     * @param depName 部门名称
     * @param pageable 是否分页
     * @return 分页数据
     */
    @Query("SELECT e FROM Employee e WHERE " +
            "(:name IS NULL OR e.name = :name) AND " +
            "(:depName IS NULL OR e.depName = :depName)")
    Page<Employee> findByOptionalParams(@Param("name") String name, @Param("depName") String depName, Pageable pageable);

    /**
     * 根据部门id查询部门下属员工
     * @param depId 部门id
     * @return 与depId关联部门的下属员工
     */
    List<Employee> findByDepId(Integer depId);

}
